﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

using AimGameEngine.NodeEditorObject;
using AimGameLibrary.GameObject;
namespace AimGameEngine.NodeEditorObject
{
    partial class PropretyIfelse : Form
    {
        NodeIfelse myNode;
        public PropretyIfelse(NodeIfelse myNode)
        {
            InitializeComponent();
            this.myNode = myNode;

            if (myNode.nodeObject1 != null)
            {
                this.ParameterBox1.Items.Add(myNode.nodeObject1.MyData.MyName);
                this.ParameterBox1.SelectedIndex = 0;
                this.ParameterBox1.Enabled = false;
            }

            if (myNode.nodeObject2 != null)
            {
                this.ParameterBox2.Items.Add(myNode.nodeObject2.MyData.MyName);
                this.ParameterBox2.SelectedIndex = 0;
                this.ParameterBox2.Enabled = false;
            }

            Relational myrelational = new Relational();
            foreach (String s in myrelational.GetrelationL)
            {
                this.RelationalBox.Items.Add(s);

                if(myNode.nodeObject1 !=null)
                    if (myNode.nodeObject1.GetType() == typeof(NodeKeyController) || myNode.nodeObject1.GetType() == typeof(NodeButtonController))
                        if (s == "!=")
                            break;

                if(myNode.nodeObject2 != null)
                    if (myNode.nodeObject2.GetType() == typeof(NodeKeyController) || myNode.nodeObject2.GetType() == typeof(NodeButtonController))
                        if (s == "!=")
                            break;
            }

            #region If Keycontroller Input
            if (myNode.nodeObject1 != null)
                if (myNode.nodeObject1.GetType() == typeof(NodeKeyController) || myNode.nodeObject1.GetType() == typeof(NodeButtonController))
                {
                    NodeController controller = (NodeController)myNode.nodeObject1;
                    if (controller.InputMode == AimGameLibrary.NodeInputMode.Isdown_Isup)
                    {
                        this.ParameterBox2.Items.Add(StateKey.IsDown.ToString());
                        this.ParameterBox2.Items.Add(StateKey.IsUp.ToString());
                    }
                    else if (controller.InputMode == AimGameLibrary.NodeInputMode.Pressed_Release)
                    {
                        this.ParameterBox2.Items.Add(StateKey.Pressed.ToString());
                        this.ParameterBox2.Items.Add(StateKey.Release.ToString());
                    }
                    ParameterBox2.SelectedIndex = 0;
                }

            if (myNode.nodeObject2 != null)
                if (myNode.nodeObject2.GetType() == typeof(NodeKeyController) || myNode.nodeObject2.GetType() == typeof(NodeButtonController))
                {
                    NodeController controller = (NodeController)myNode.nodeObject2;
                    if (controller.InputMode == AimGameLibrary.NodeInputMode.Isdown_Isup)
                    {
                        this.ParameterBox1.Items.Add(StateKey.IsDown.ToString());
                        this.ParameterBox1.Items.Add(StateKey.IsUp.ToString());
                    }
                    else if (controller.InputMode == AimGameLibrary.NodeInputMode.Pressed_Release)
                    {
                        this.ParameterBox1.Items.Add(StateKey.Pressed.ToString());
                        this.ParameterBox1.Items.Add(StateKey.Release.ToString());
                    }
                    ParameterBox1.SelectedIndex = 0;
                }
            #endregion

            this.RelationalBox.SelectedItem = myNode.SelectRelational;
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            myNode.SelectRelational = (String)this.RelationalBox.SelectedItem;

            if (myNode.nodeObject1 != null)
                if (myNode.nodeObject1.GetType() == typeof(NodeKeyController) || myNode.nodeObject1.GetType() == typeof(NodeButtonController))
                    myNode.Result = (String)this.ParameterBox2.SelectedItem;

            if (myNode.nodeObject2 != null)
                if (myNode.nodeObject2.GetType() == typeof(NodeKeyController) || myNode.nodeObject2.GetType() == typeof(NodeButtonController))
                    myNode.Result = (String)this.ParameterBox1.SelectedItem;

        }

    }
}
